//
//  ByDayEarningApplySuccessVC.m
//  mijifen_ios
//
//  Created by mc on 2017/10/30.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByDayEarningApplySuccessVC.h"
// cell
#import "ByCellDayEarningApplyRecord.h"

// view
#import "ByViewHeaderSuccess.h"


@interface ByDayEarningApplySuccessVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *dataArray;
@end

@implementation ByDayEarningApplySuccessVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"申请成功";
    [self addLeftBackBarButtonItem];
    [self createViews];
    [self fetchData];

}

#pragma mark - getter
- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

#pragma mark - 创建成功
- (void)createViews{
    ByViewHeaderSuccess *headerView = [[ByViewHeaderSuccess alloc] initWith:@"DayEarning_succuess" title:@"申请成功"];
    [self.view addSubview:headerView];
    __block CGFloat height;
    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        if (@available(iOS 11.0,*)) {
            height = (self.view.height - 50 * 2 - 10 - self.view.safeAreaInsets.bottom) / 2;
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, height));
        }else{
            height = (self.view.height - 50 * 2 - 10) / 2;
            make.top.equalTo(self.view.mas_top);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, height));
        }
        
    }];
    
    UIButton *backButton = [[UIButton alloc] init];
    [self.view addSubview:backButton];
    [backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        if (@available(iOS 11.0,*)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
        }else{
            make.bottom.equalTo(self.view.mas_bottom);
        }
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 50));
    }];
    [backButton setTitle:@"返回首页" forState:UIControlStateNormal];
    [backButton setTitleColor:BY_TEXT_COLOR forState:UIControlStateNormal];
    [backButton setBackgroundColor:BY_THEME_COLOR];
    
    self.tableView = [[UITableView alloc] init];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headerView.mas_bottom);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(backButton.mas_top);
    }];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.backgroundColor = BY_TABLE_COLOR;

}

#pragma mark - 获取数据
- (void)fetchData{
    for (int i = 0; i < 10; i ++) {
        ByModelDayEarning *model = [[ByModelDayEarning alloc] init];
        model.prcie = @"2100";
        model.shop_name = @"杭州博✌️";
        model.resource = @"微信退款";
        model.create_time = @"2017-10-26 12:12:10";
        [self.dataArray addObject:model];
    }
    [self.tableView reloadData];
}

#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ByCellDayEarningApplyRecord *cell = [ByCellDayEarningApplyRecord cellWithTableView:tableView];
    cell.model = self.dataArray[indexPath.section];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 75;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 30;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 20;
    }
    return 0.0001;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
    footerView.backgroundColor = BY_TABLE_COLOR;
    UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH - 20, 20)];
    timeLabel.textAlignment = NSTextAlignmentRight;
    timeLabel.font = FONT(16);
    [footerView addSubview:timeLabel];
    ByModelDayEarning *model = self.dataArray[section];
    timeLabel.text = model.create_time;
    return footerView;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
